//
//  CViewController.m
//  Category
//
//  Created by Burn on 2020/1/8.
//  Copyright © 2020 menksoft. All rights reserved.
//

#import "CViewController.h"
#import "UIScrollView+Refresh.h"
@interface CViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(strong,nonatomic) UICollectionView *collectionView;
@end

@implementation CViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.collectionView];
    self.collectionView.mk_left = [MKRefreshLeftView leftWithRefreshingTarget:self refreshingAction:@selector(refresh)];
//    self.collectionView.mk_rigth = [MKRefreshRightView rightWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
}


- (void)refresh{
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.collectionView.mk_left endRefreshing];
    });
    
}

- (void)loadMore{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.collectionView.mk_rigth endRefreshing];
    });
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 20;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ID" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255) / 255.0 green:arc4random_uniform(255) / 255.0 blue:arc4random_uniform(255) / 255.0 alpha:1];
    return cell;
}


- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.minimumLineSpacing = 5;
        layout.minimumInteritemSpacing = 0;
        layout.itemSize = CGSizeMake(50, self.view.bounds.size.height - 88);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 88, self.view.frame.size.width, self.view.bounds.size.height - 88) collectionViewLayout:layout];
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"ID"];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
    }
    return _collectionView;
}




@end
